﻿using System;

namespace Orz.Framework.Core.Messaging
{
    /// <summary>
    /// The messenger depend on message type.
    /// </summary>
    public class TypeMessenger : Messenger<Type>
    {
        /// <summary>
        /// Notifies all registered parties that a message is being broadcasted.
        /// </summary>
        /// <param name="obj">The obj.</param>
        public void NotifyAll(object obj)
        {
            if (obj != null)
                base.NotifyAll(obj.GetType(), obj);
        }

        /// <summary>
        /// Notifies all registered parties that a message is being broadcasted, the process is asynchronous.
        /// </summary>
        /// <param name="obj">The obj.</param>
        public void NotifyAllAsyn(object obj)
        {
            if (obj != null)
                base.NotifyAllAsyn(obj.GetType(), obj);
        }

        /// <summary>
        /// Subscribe a callback method, with no parameter, to be invoked when a specific message is broadcasted.
        /// </summary>
        /// <typeparam name="T">The type.</typeparam>
        /// <param name="callback">The callback to be called when this message is broadcasted.</param>
        public void Subscribe<T>(Delegate callback)
        {
            Subscribe(typeof(T), callback);
        }
    }
}
